
POWERUP_REGEN = "Regeneration"
POWERUP_RESIST = "Fire Resistance"
POWERUP_INFRAVISION = "Infravision"
POWERUP_HORDE = "Horde Strength"
POWERUP_RADIATION = "Radiation"
POWERUP_ACCESS = "Unlocked Classes"

// Each powerup is called every 3 seconds
Powerups = {}

Powerups.List = {POWERUP_REGEN,
POWERUP_RESIST,
POWERUP_INFRAVISION,
POWERUP_HORDE,
POWERUP_RADIATION,
POWERUP_ACCESS}

Powerups[POWERUP_REGEN] = function(ply)
	ply:AddHealth(25)
end

Powerups[POWERUP_RESIST] = function(ply)
	ply.FireImmune = true
end

Powerups[POWERUP_HORDE] = function(ply)
	local npcnum = 0
	for k,npc in pairs(ents.FindByClass("npc_*")) do
		if npc:GetPos():Distance(ply:GetPos()) < 700 then
			npc:SetHealth(math.Clamp(npc:Health() + 5,0,npc.MaxHealth or 50))
			if math.random(1,3) == 1 then
				npc:VoiceSound(ChooseRandom(npc.Taunt),100)
			end
			npcnum = npcnum + 1
		end
	end
	if npcnum >= 10 then
		ply:AddHealth(5)
		ply:VoiceSound(ChooseRandom(ply.Taunt),100,math.Rand(0.1,2))
	end
	for k,v in pairs(player.GetAll()) do
		if v:Team() == TEAM_UNDEAD then
			if v:GetPos():Distance(ply:GetPos()) < 700 and v != ply then
				if math.random(1,3) == 1 then
					v:VoiceSound(ChooseRandom(v.Taunt),100,math.Rand(0.1,2))
				end
			end
		else
			if v:GetPos():Distance(ply:GetPos()) < 700 then
				if math.random(1,3) == 1 then
					v:VoiceSound(ChooseRandom(v.Alert),100,math.Rand(0.1,2))
				end
				v:TakeStamina(5)
			end
		end
	end
end

Powerups[POWERUP_RADIATION] = function(ply)
	for k,v in pairs(player.GetAll()) do
		if v:Team() == TEAM_HUMANS then
			if v:GetPos():Distance(ply:GetPos()) < 600 then
				if v.RadiationTimer then 
					if v.RadiationTimer < CurTime() then
						local chance = 40
						if v:Health() != v.MaxHealth then
							chance = 30
						end
						if v:Health() < v.MaxHealth / 2 or v.Cutter or v.Infector then
							chance = 20
						end
						if math.random(1,chance) == 1 then
							v:DoPoison()
							v:ClientSound(ChooseRandom(GameSounds.Geiger))
						else
							v:ClientSound(ChooseRandom(GameSounds.Geiger))
						end
						v.RadiationTimer = CurTime() + 1.9
						if v.FvoxDelay then
							if v.FvoxDelay < CurTime() then
								v:ClientSound(FVOX.Radiation)
								v.FvoxDelay = CurTime() + 15
							end
						else
							v.FvoxDelay = CurTime() + 5
						end
					end
				else
					v.RadiationTimer = CurTime() + 1
				end
			end
		elseif v:Team() == TEAM_UNDEAD and v != ply then
			if v:GetPos():Distance(ply:GetPos()) < 700 then
				v:AddHealth(5)
			end
		end
	end
end

Powerups[POWERUP_ACCESS] = function(ply)
	umsg.Start("UnlockClass", ply)
	umsg.Float(1.0)
	umsg.End() 
end

Powerups[POWERUP_INFRAVISION] = function(ply)
	if not ply.HasInfra then
		ply.HasInfra = true
		umsg.Start("GiveInfra", ply)
		umsg.End() 
	end
end

Powerups.Timer = 0
function PowerupsThink()
	if Powerups.Timer < CurTime() then
		Powerups.Timer = CurTime() + 3
		for k,v in pairs(team.GetPlayers(TEAM_UNDEAD)) do
			if v:Alive() then
				v.Powerups = v.Powerups or {}
				for c,d in pairs(v.Powerups) do
					Powerups[d](v)
				end
			end
		end
	end
end
hook.Add( "Think", "PowerupsThink", PowerupsThink )
